package question5;

public class Main {

    public int huiWen(String word) {
        char[] charArray = word.toCharArray();
        int beginIndex = 0, endIndex = charArray.length-1;
        while (beginIndex < endIndex) {
            while (beginIndex < endIndex &&  !isMatch(charArray[beginIndex])) {
                beginIndex++;
            }
            while (beginIndex < endIndex && !isMatch(charArray[endIndex])) {
                endIndex--;
            }
            if (!isEqual(charArray[beginIndex], charArray[endIndex])) {
                return 0;
            }
            beginIndex++;
            endIndex--;
        }
        return 1;
    }

    public static boolean isMatch(char c) {
        if ( (c >= 'a' && c <= 'z') ||  (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) {
            return true;
        }
        return false;
    }

    public static boolean isEqual(char a, char b) {
        return a == b || a + 32 == b || a - 32 == b;
    }

    public static void main(String[] args) {
        int i = new Main().huiWen("a");
        System.out.println(i);
    }
}
